package pers.zc.activiti.shujujiegou.duilie;

/**
 * @Annotion:
 * @ClassName: Duilie
 * @Author: Lin Fuyuan
 * @Date: 2019/11/20  18:38
 * @Version: 1.0
 */
public class Duilie {

    private Integer[] dui ;
    private int start ;
    private int end;
    Duilie(int num){
        dui = new Integer[num];
        start = 0;
        end  = 0;
    }


    public boolean setDuilie(Integer x){
        //如果 开始和结束差  大于等于长度,
        if(start>=dui.length){
            //到尾部了
            if(start - end >= dui.length){
                //满了
                return false;
            }
            //数据转移
            int w = end;
            for(int i = end ;i<start;i++){
                dui[i-w] = dui[i];
                dui[i] = null;
            }
            end = 0;
            start = start -w;
        }

        dui[start] =x;
        start++;
        return true;
    }



    public Integer getDuilie(){
        if(end == start){
            return null;
        }
        Integer y = dui[end];
        dui[end] = null;
        end ++;
        return y;
    }


}
